package org.csu.mybigpro.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import jakarta.annotation.Resource;
import org.csu.mybigpro.domain.Training;
import org.csu.mybigpro.persistence.TrainingMapper;
import org.csu.mybigpro.service.TrainingService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Map;

@Service
public class TrainingServiceImpl implements TrainingService {
    @Resource
    private TrainingMapper trainingMapper;

    @Override
    public boolean addTraining(Training training) {
        // insert 返回影响行数，>0 表示成功
        return trainingMapper.insert(training) > 0;
    }

    @Override
    public boolean updateTraining(Training training) {
        // updateById 返回影响行数
        return trainingMapper.updateById(training) > 0;
    }

    @Override
    public boolean deleteTrainingById(Long id) {
        // deleteById 返回影响行数
        return trainingMapper.deleteById(id) > 0;
    }

    @Override
    public List<Training> getTrainingsByName(String name) {
        QueryWrapper<Training> queryWrapper = new QueryWrapper<>();
        if (name != null && !name.isEmpty()) {
            queryWrapper.like("name", name); // 模糊查询name字段
        }
        return trainingMapper.selectList(queryWrapper);
    }

    @Override
    public List<Training> getTrainingsByCourse(String course) {
        QueryWrapper<Training> queryWrapper = new QueryWrapper<>();
        if (course != null && !course.isEmpty()) {
            queryWrapper.like("course", course); // 模糊查询name字段
        }
        return trainingMapper.selectList(queryWrapper);
    }

    @Override
    public List<Training> getTrainingsByType(String type) {
        QueryWrapper<Training> queryWrapper = new QueryWrapper<>();
        if (type != null && !type.isEmpty()) {
            queryWrapper.like("type", type); // 模糊查询name字段
        }
        return trainingMapper.selectList(queryWrapper);
    }

    @Override
    public List<Training> getTrainingsByStatus(String status) {
        QueryWrapper<Training> queryWrapper = new QueryWrapper<>();
        if (status != null && !status.isEmpty()) {
            queryWrapper.like("status", status); // 模糊查询name字段
        }
        return trainingMapper.selectList(queryWrapper);
    }

    @Override
    public List<Training> getTrainingsByManager(String manager) {
        QueryWrapper<Training> queryWrapper = new QueryWrapper<>();
        if (manager != null && !manager.isEmpty()) {
            queryWrapper.like("manager", manager); // 模糊查询name字段
        }
        return trainingMapper.selectList(queryWrapper);
    }

    @Override
    public List<Training> getAllTrainings() {
        // 不带条件查询全部
        return trainingMapper.selectList(null);
    }
}
